//2865.美丽塔I
//https://leetcode.cn/problems/beautiful-towers-i/?envType=daily-question&envId=2024-01-24
class Solution {
public:
    long long maximumSumOfHeights(vector<int>& maxHeights) {
        int n = maxHeights.size();
        long long ret = 0;
        for (int i = 0; i < n; ++i)
        {
            long long num = maxHeights[i];
            long long prev = maxHeights[i];
            for (int k = i - 1; k >= 0; --k)
            {
                if (maxHeights[k] > prev) num += prev;
                else num += maxHeights[k], prev = maxHeights[k];
            }
            prev = maxHeights[i];
            for (int k = i + 1; k < n; ++k)
            {
                if (maxHeights[k] > prev) num += prev;
                else num += maxHeights[k], prev = maxHeights[k];
            }
            ret = max(ret, num);
        }
        return ret;
    }
};